import { runAsWorker } from "synckit";

export type ResolvePrettierFileInfoFn = (onDiskFilepath: string, prettierPlugins?: string[]) => import("prettier").FileInfoResult;

let prettier: typeof import("prettier");

runAsWorker(async (onDiskFilepath: string, prettierPlugins?: string[]) => {
  if (!prettier) {
    prettier = await import("prettier");
  }

  const prettierFileInfo = await prettier.getFileInfo(onDiskFilepath, {
    resolveConfig: false,
    withNodeModules: false,
    ignorePath: ".prettierignore",
    plugins: prettierPlugins ? (prettierPlugins as string[]) : void 0,
  });

  // Skip if file is ignored using a .prettierignore file
  return prettierFileInfo;
});
